package com.goldsprite.gameframeworks.ecs;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import com.goldsprite.gameframeworks.log.*;

public interface IRunnable {
	void update(float delta);
	void fixedUpdate(float fixedDelta);


	public static AtomicInteger runnableGidSeed = new AtomicInteger(0);

	IRunnableFields getIRunnableFields();

	default void initIRunnable() {
		int newId = runnableGidSeed.getAndAdd(1);
		Debug.logT("IRunnable", "新可运行对象%s，Gid: %s", getName(), newId);
		initRunnableGid(newId);
	}

	default void initRunnableGid(int gid) {
		if(getIRunnableFields().runnableGid != -1) return;

		getIRunnableFields().runnableGid = gid;
	}

	default int getRunnableGid() {
		return getIRunnableFields().runnableGid;
	}

	default <T> T setName(String name) {
		getIRunnableFields().name = name;
		return (T)this;
	}
	default String getName() {
		if(getIRunnableFields().name == null || getIRunnableFields().name.isBlank())
			getIRunnableFields().name = getClass().getSimpleName();
		return getIRunnableFields().name;
	}

	public static class IRunnableFields {
		public String name;
		protected int runnableGid = -1;
	}
}
